-
Notifications
You must be signed in to change notification settings - Fork 7.7k
drivers: timer: nrf_rtc_timer: Allow use of custom bit width #92025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: timer: nrf_rtc_timer: Allow use of custom bit width #92025
Conversation
adf0eae
to
a5fde6a
Compare
e351fa8
to
1664818
Compare
Out of curiosity, what usecases are there for artificially lowering the counters bit widht? Only effect I can think of is more frequent wakeups to account for rollover, which would be worse for power consumption :) |
d40e414
to
35cf7eb
Compare
35cf7eb
to
77881ce
Compare
Allowed use of counter bit width lower than hardware 24. In that case, PPI connection is established to trigger clear task once maximum value is reached. Signed-off-by: Michał Stasiak <michal.stasiak@nordicsemi.no>
Added overlay for the board. Signed-off-by: Michał Stasiak <michal.stasiak@nordicsemi.no>
77881ce
to
e387528
Compare
|
config NRF_RTC_COUNTER_BIT_WIDTH | ||
int | ||
default 15 if SOC_NRF52832 | ||
default 24 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range x 24
@@ -17,11 +17,21 @@ | |||
#include <haly/nrfy_rtc.h> | |||
#include <zephyr/irq.h> | |||
|
|||
/* Ensure that selected counter bit width is within its maximum hardware width. */ | |||
BUILD_ASSERT(CONFIG_NRF_RTC_COUNTER_BIT_WIDTH <= 24, "Counter bit width exceeds maximum width."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUILD_ASSERT(CONFIG_NRF_RTC_COUNTER_BIT_WIDTH <= 24, "Counter bit width exceeds maximum width."); | |
BUILD_ASSERT(CONFIG_NRF_RTC_COUNTER_BIT_WIDTH <= RTC_BIT_WIDTH, "Counter bit width exceeds maximum width."); |
If range
is added in Kconfig then it is redundant.
/* Ensure that selected counter bit width is within its maximum hardware width. */ | ||
BUILD_ASSERT(CONFIG_NRF_RTC_COUNTER_BIT_WIDTH <= 24, "Counter bit width exceeds maximum width."); | ||
|
||
#if (CONFIG_NRF_RTC_COUNTER_BIT_WIDTH < 24) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if (CONFIG_NRF_RTC_COUNTER_BIT_WIDTH < 24) | |
#if (CONFIG_NRF_RTC_COUNTER_BIT_WIDTH < RTC_BIT_WIDTH) |
@@ -33,7 +43,7 @@ BUILD_ASSERT(CHAN_COUNT <= CHAN_COUNT_MAX, "Not enough compare channels"); | |||
BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), | |||
"Counter for RTC1 must be disabled"); | |||
|
|||
#define COUNTER_BIT_WIDTH 24U | |||
#define COUNTER_BIT_WIDTH CONFIG_NRF_RTC_COUNTER_BIT_WIDTH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to have
#define RTC_BIT_WIDTH 24
@@ -560,8 +590,13 @@ void rtc_nrf_isr(const void *arg) | |||
rtc_pretick_rtc1_isr_hook(); | |||
} | |||
|
|||
if (nrfy_rtc_int_enable_check(RTC, NRF_RTC_INT_OVERFLOW_MASK) && | |||
nrfy_rtc_events_process(RTC, NRF_RTC_INT_OVERFLOW_MASK)) { | |||
if ((nrfy_rtc_int_enable_check(RTC, NRF_RTC_INT_OVERFLOW_MASK) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to check OVERFLOW event if custom bit width is used.
@@ -742,7 +781,7 @@ static int sys_clock_driver_init(void) | |||
|
|||
int_mask = BIT_MASK(CHAN_COUNT); | |||
if (CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT) { | |||
alloc_mask = BIT_MASK(EXT_CHAN_COUNT) << 1; | |||
alloc_mask = BIT_MASK(EXT_CHAN_COUNT) << (1 + CUSTOM_COUNTER_BIT_WIDTH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With potentially 2 internal channels It would be good to define
#define SYS_CLOCK_CH 0
#define WRAP_CH 1
And use it here and in places where 0 and 1 are used explicitly now.
Allowed use of counter bit width lower than hardware 24. In that case, PPI connection is established to trigger clear task once maximum value is reached.